var RM007 = {};

RM007.loadDataTable = function(isSearch) {
    
    $('#dataTable')
	    .dataTable(
		    {
			bDestroy : true,
			bProcessing : false,
			bServerSide : true, 
			bLengthChange : false,
			bFilter : false,
			sAjaxSource : "getRM007DataTable",
			fnServerParams : function(aoData) {
			  
			    aoData.push(
				    /*---- For Tower Search ----*/
				    {
        				"name" : "model.rlsttower",
        				"value" : $('#tower').val()
				    }, {
					"name" : "model.rlstfloor",
					"value" : $('#floor').val()
				    }, {
					"name" : "model.rlstunitno",
					"value" : $('#unitNo').val()
				    }, {
					"name" : "model.rlstaddr",
					"value" : $('#address').val()
//				    }, 
				    /*---- For Other Search ----*/
//				    {
//        				"name" : "model.accridusrno",
//        				"value" : $('#accridusrno').val()
//				    }, {
//					"name" : "model.accrcrdid",
//					"value" : $('#accrcrdid').val()
//				    }, {
//					"name" : "model.accrlrno",
//					"value" : $('#accrlrno').val()
//				    }, {
//					"name" : "model.accrstat",
//					"value" : $('#status').val()
				    });
			},
			columns : [ {
			    "data" : "rlrmid",
			    "sClass" : "center"
			}, {
			    "data" : "rlsttower",
			    "sClass" : "center"
			}, {
			    "data" : "rlstfloor",
			    "sClass" : "center"
			}, {
			    "data" : "rlstunitno" ,
			    "sClass" : "center"
			}, {
			    "data" : "rlstaddr",
			    "sClass" : "center"
			}, {
			    "data" : "ownModel.rownfsenm",
//			    "sClass" : "center"
			}, {
			    "data" : "tntModel.rtntfsenm",
//			    "sClass" : "center"
//			}, {
//			    "data" : "accrstat",
//			    "sClass" : "center"
			} ],
			aaSorting: [[1, 'asc']]
			,
    		columnDefs : [
    			{
    			    render : function(data, type, row) {
    				return  data? '<a href=RM007A?rlrmid='+row['rlrmid']+'&#tabs-1>'+data+'</a>' : ' - ';
    			    },
    			    targets : 5
    			},
    			{
    			    render : function(data, type, row) {
    				return  data? '<a href=RM007A?rlrmid='+row['rlrmid']+'&#tabs-2>'+data+'</a>' : ' - ';
    			    },
    			    targets : 6
    			},
//    			{
//    			    render : function(data, type, row) {
//    				return _COMMON.StatusRender[data];
//    			    },
//    			    targets : 8
//    			},
    			{
    			    render : function(data, type, row) {
    				return _COMMON.ButtonRender.editBtn(
    					'RM007.onEdit(\'' + data + '\')',
    					null)
    					+ '&nbsp;'
    					+ _COMMON.ButtonRender.delBtn(
    						'RM007.onDelete(\'' + data
    							+ '\')',
    						_COMMON.isRoomHide);
    			    },
    			    targets : 0
    			}, {
    			    'bSortable' : false,
    			    'aTargets' : [ 0 ]
			} ],
    });

};

RM007.onDelete = function(name) {

$("#confirm").html("Do you want to delete ?");

$("#confirm").dialog({
    resizable: false,
    modal: true,
    title: "Confirm Delete",
    height: 180,
    width: 300,
    buttons: {
        "Yes": function () {
            $(this).dialog('close');
            location = 'RM007ADelete?cardId='+name;
        },
            "No": function () {
            $(this).dialog('close');
        }
    }
});
};

RM007.onEdit = function(id) {
    location = 'RM007A?rlrmid='+id;
};

RM007.init = function() {
    
    _COMBOBOX.RoomStatusCombo('roomStatus');
    _COMBOBOX.OwnerTenantCombo('ownType');
    
    _COMBOBOX.TowerFloorUnitAddrCombo('tower', 'floor' , 'unit' , 'address');

};

RM007.clearHeaderCriteria = function(){

   $('#ownType').clear();
   $('#roomStatus').clear();
  
  _COMBOBOX.ResetAllTowerCriteria('tower', 'floor' , 'unit' , 'address');

};

$(document).ready(function() {
    
    _log(' ######## --- RM007 -------######');
    
    RM007.init();
    
    RM007.loadDataTable();
    
    $("#btnClear").click(function() {
	RM007.clearHeaderCriteria();
    });
    
    $("#btnSearch").click(function() {
    	 RM007.loadDataTable();
    });
});

